<?php

namespace app\api\model;

use addons\epay\library\Service;
use think\Db;
use think\Model;

class Order extends Model
{
    // 表名
    protected $name = 'order';


    public function createOrder($uid, $params)
    {
        $orderSn = get_order_sn("o_");
        $goods = Goods::get($params['goods_id']);
        $data = [
            'order_sn' => $orderSn,
            'activity_id' => $params['activity_id'],
            'goods_id' => $params['goods_id'],
            'price' => $goods['price'],
            'player_id' => $params['player_id'],
            'wish' => $params['wish'],
            'vote_number' => $goods['vote_number'],
            'create_time' => time(),
            'status' => 0,
            'user_id' => $uid,
            'goods_name'=>$goods['name']
        ];
        $id = self::save($data);
        $data['id'] = $id;
        return $data;
    }

    public static function orderPay($uid, $orderInfo, $notifyurl,$method='mp')
    {
        $openId = Db::name("third")->where("user_id", $uid)->value("openid");
        $pay = Service::submitOrder($orderInfo['price'], $orderInfo['order_sn'], 'wechat', $orderInfo['goods_name'], $notifyurl, null,$method, $openId);
        return $pay;
    }
}